# 从student.txt文件中读取相关数据

dic = {}
with open("student.txt", 'r') as fp:
    data = fp.readlines()  # data是列表
    # 使用for-in循环遍历data中每个元素
    for i in data:
        names, likes = i.split(" ")  # split() 按照某一规则拆分字符串
        # print(likes)
        like = likes.replace("\n", "")  # 将换行符替换成空字符串
        s = like.split(",")
        # print(s) # s列表
        # 统计每一种爱好的次数
        for j in s:
            # print(j) # 每种爱好名称，当作key
            if j not in dic:
                dic[j] = 0  # 添加
            # dic[j] = dic[j] + 1
            dic[j] += 1
print(dic)
